package com.smartfast4j.manager.modules.sys.controller;

import com.smartfast4j.common.bean.R;
import com.smartfast4j.manager.common.controller.ManagerBaseController;
import com.smartfast4j.manager.modules.sys.service.SysConfigService;
import com.smartfast4j.pojo.sys.SysConfig;
import com.smartfast4j.pojo.sys.SysConfigExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* SysConfigController
*  由代码生成器生成
*/
@RestController
@RequestMapping("/sysConfig")
public class SysConfigController extends ManagerBaseController {

    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 新增
     *
     */
    @RequestMapping("/add")
    public R add(SysConfig sysConfig) {
         sysConfigService.insertSelective(sysConfig);
         return R.ok();
    }

    /**
     * 修改
     *
     */
    @RequestMapping("/update")
    public R update(SysConfig sysConfig) {
        sysConfigService.updateByPrimaryKeySelective(sysConfig);
        return R.ok();
    }

    /**
     * 删除
     *
     */
    @RequestMapping("/delete")
    public R delete(Long id) {
        sysConfigService.deleteByPrimaryKey(id);
        return R.ok();
    }

    /**
     * 查询所有
     *
     */
    @RequestMapping("/list")
    public R list(){
         List<SysConfig> dataList = sysConfigService.selectByExample(null);
         return R.ok(dataList);
    }

     /**
     * 分页查询
     *
     */
    @RequestMapping("/pageList")
    public R pageList(@RequestParam(defaultValue = "1")int pageNum, @RequestParam(defaultValue = "10")int pageSize){
        SysConfigExample example = new SysConfigExample();
        //分页查询
        example.setLimitStart((pageNum-1) * pageSize);//从第几条开始取（索引从0开始）
        example.setLimitEnd(pageSize);//取多少条
        List<SysConfig> dataList = sysConfigService.selectByExample(example);
        return R.ok(dataList);
    }
}
